package com.bst.bsj.jetty.server;

import org.apache.log4j.Logger;

import com.bst.bsj.spring.util.AppSettings;

public class JettyServerLauncher {

	private static final Logger logger = Logger
			.getLogger(JettyServerLauncher.class);

	public static void main(String[] args) throws Exception {
		AppSettings.getInstance().init("webapp-config.properties");
		JettyServer server = new JettyServer();
		Runtime.getRuntime().addShutdownHook(
				new Thread(new MetadataShutdownTask(server)));
		server.run();
	}

	private static class MetadataShutdownTask implements Runnable {

		private JettyServer server;

		public MetadataShutdownTask(JettyServer server) {
			this.server = server;
		}

		public void run() {
			try {
				server.stop();
			} catch (Exception e) {
				logger.error("Caught exception when stopping dispatch server. Error:"
						+ e);
			}
		}
	}
}
